package com.luoran.car.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.luoran.car.config.Result;
import com.luoran.car.domain.PromotionSpace;
import com.luoran.car.service.PromotionSpaceService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/promotion")
public class PromotionSpaceController {
    @Autowired
    private PromotionSpaceService promotionSpaceService;

    @RequestMapping("list")
    public Result list(Integer current,Integer size,@RequestBody PromotionSpace promotionSpace){
        PageHelper.startPage(current, size);
        List<PromotionSpace> list= promotionSpaceService.list1(promotionSpace);
        return  Result.success(new PageInfo<>(list));
    }
    @RequestMapping("add")
    public Result add(@RequestBody PromotionSpace promotionSpace){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        promotionSpace.setCreatetime((simpleDateFormat.format(new Date())));
        boolean save = promotionSpaceService.save(promotionSpace);
        return save? Result.success():Result.fail();
    }

}



